package net.youyi.crazycopyer.ui;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.BackgroundColorSpan;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.EditText;

import net.youyi.crazycopyer.R;

/**
 * Created by xzp on 15/12/22.
 */
public class EditTextActivity extends BaseActivity{
    private EditText mEditText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);
        mEditText= (EditText) this.findViewById(R.id.edit_text);
    }
    public void onClick(View view){
        SpannableStringBuilder builder=new SpannableStringBuilder("@");
        builder.setSpan(new ImageSpan(this,getBitmap()), 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
       // builder.append(mEditText.getText());
        mEditText.append(builder,0,builder.length());
    }
    private Bitmap getBitmap(){
        String string="这尼玛我CAO ";
        Paint paint=mEditText.getPaint();
        Rect rect=new Rect();
        paint.getTextBounds(string,0,string.length(),rect);
        Bitmap bitmap=Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas=new Canvas(bitmap);
        canvas.drawText(string,0,30,paint);
        return bitmap;
    }
}
